
clear all
cd "_______"
*dataset.dta is the wide version of the original dataset (confidential)
use  "dataset.dta", clear

xtset premise_id sasdate

gen month=month(sasdate)
gen year=year(sasdate)
gen dow=dow(sasdate)
gen week=week(sasdate)
gen yearmo=100*year+month
gen yearwk=100*year+week

keep if month>4&month<10

forvalues i=1/24{
  qui reghdfe kwh_`i', absorb(premise_id yearmo) cluster(yearwk) resid
  predict twfe_kwh_`i', res
  qui reghdfe temp_`i', absorb(premise_id yearmo) resid
  predict twfe_temp_`i', res
  preserve
  collapse (mean) twfe_kwh_`i' twfe_temp_`i', by(sasdate)
  graph twoway (lfit twfe_kwh_`i' twfe_temp_`i') (scatter twfe_kwh_`i' twfe_temp_`i'), ytitle("Residuals: KWH `i'") xtitle("Residuals: Temperature `i'") legend(off)
  graph export FigureB2B3B4_`i'.pdf, replace
  restore
}
